#ifndef TCP_SERVER_H
#define TCP_SERVER_H 1

#include <unistd.h>
#include <iostream>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <pthread.h>
#include "MessageQueue.h"

#define MAXSIZE 100
#define BUF_SIZE 1024

class tcp_server
{
private:
    int socket_fd;
    int max_socket_fd;
    sockaddr_in myserver;
    sockaddr_in remote_addr;
	pthread_t recv_thread_id, accept_thread_id, send_thread_id;

	int socket_array[MAXSIZE];
	char buf [BUF_SIZE];

	MessageQueue *_message_queue;
	MessageQueue *_recv_message_queue;

	// void *accept_msg(void *ptr)
	void recv_buffer(int socket_fd);
	void accept_socket(int socket_fd);

public:
	void recv_msg();
	void send_msg();

    tcp_server(int listen_port);
    bool start_recv_msg(MessageQueue * mq);
    bool stop_recv_msg();

    bool start_send_msg(MessageQueue * mq);
	bool stop_send_msg();
};


#endif